home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / DINKDEMO / DC_TEXTE / DTEDITWI.C < prev    next >
Text File  |  1992-07-07  |  4KB  |  213 lines

  1. /*
  2.     File:        DTEditWindow.c
  3.  
  4.     Written by:    Mark Gross
  5.  
  6.     Copyright:    ⌐ 1992 by Applied Technical Software, all rights reserved.
  7.     Use at your own risk.
  8.  
  9. */
  10.  
  11. // This is the class definition of DTEditWind
  12.  
  13. #include "DTEditDoc.h"
  14. #include "DTEditWind.h"
  15. #include "DApplication.h"
  16.  
  17. Boolean DTEditWind::Init(DDocument *doc, Boolean hasColorWindows)
  18. {
  19.     Boolean inheritedSuccess;
  20.     Rect vRect;
  21.     
  22.     inheritedSuccess = inherited::Init(doc, hasColorWindows);
  23.  
  24.     fDocText = ((DTEditDoc*)doc)->fText;
  25.     
  26.     fNextHandler = doc;
  27.     SetPort(fWindowPtr);
  28.     ( *fDocText)->inPort = fWindowPtr;
  29.     ( *fDocText)->txSize = 9;
  30.     ( *fDocText)->txFont = monaco;
  31.     
  32.     fVMax = (*fDocText)->nLines * (*fDocText)->lineHeight;
  33.     fVMin = 0;
  34.     
  35.     fHMax = ( (*fDocText)->destRect.right - (*fDocText)->destRect.left );
  36.     fHMin = 0;
  37.     
  38.     return (inheritedSuccess);
  39. }// end of init function
  40.  
  41.  
  42.  
  43. void DTEditWind::SynchScrollBars(void)
  44. {
  45.     Rect visible, dest;
  46.     
  47.     visible = (*fDocText)->viewRect;
  48.     dest = (*fDocText)->destRect;
  49.  
  50.     fVMax = (*fDocText)->nLines * (*fDocText)->lineHeight;
  51.     fVMin = 0;
  52.     
  53.     fVOffSet = visible.top - dest.top;
  54.     fHOffSet = visible.left - dest.left;
  55.         
  56.     inherited::SynchScrollBars();
  57. }// end of SynchScrollBars member function
  58.  
  59.  
  60.  
  61. void DTEditWind::HandleKeyDown(EventRecord *theEvent)                
  62. {
  63.     TEKey(LoWrd(theEvent->message), fDocText);
  64.     fDoc->fNeedToSave = TRUE;
  65.     SynchScrollBars();
  66.  
  67. } // end of HandleKeyDown member function
  68.  
  69.  
  70. void DTEditWind::HandleActivateEvt(EventRecord *theEvent)
  71. {
  72.     Boolean    activating;
  73.     
  74.     inherited:: HandleActivateEvt(theEvent);
  75.     
  76.     activating = (theEvent->modifiers & activeFlag);
  77.     if(activating)
  78.     {
  79.         TEActivate( fDocText );
  80.     }
  81.     else
  82.     {
  83.         TEDeactivate( fDocText );
  84.     }
  85.     
  86.     inherited:: HandleActivateEvt(theEvent);
  87.  
  88. }// end of HandleActivateEvt member function
  89.  
  90.  
  91. void DTEditWind::HandleOSEvent(EventRecord *theEvent)
  92. {
  93.     if(gApplication->fInBackground)
  94.     {
  95.         TEDeactivate( fDocText );
  96.     }
  97.     else
  98.     {
  99.         TEActivate( fDocText );
  100.     }
  101.     
  102. }// end of HandleActivateEvt member function
  103.  
  104.  
  105.  
  106. void DTEditWind::HandleNullEvent(EventRecord *theEvent)
  107. {
  108.     Rect    r;
  109.     Point whereIsMouse;
  110.     GrafPtr    oldPort;
  111.     CursHandle    IBeam;
  112.  
  113.     if (!gApplication->fInBackground)
  114.     {
  115.         GetPort(&oldPort);
  116.         SetPort(fWindowPtr);
  117.         GetMouse(&whereIsMouse);
  118.     
  119.         GetContentRect(&r);
  120.         if( PtInRect(whereIsMouse, &r) )
  121.         {
  122.             IBeam = GetCursor(iBeamCursor);
  123.             if(IBeam != NULL)
  124.                 SetCursor(*IBeam);
  125.             
  126.         }
  127.         else
  128.             InitCursor();
  129.     
  130.         SetPort(oldPort);
  131.         TEIdle( fDocText );
  132.     }// end if in forground
  133. }
  134.  
  135.  
  136.  
  137. void    DTEditWind::DoContent(EventRecord* theEvent)
  138. {    
  139.     Rect contents;
  140.     Boolean shiftOn;
  141.     Point    newPoint;
  142.     
  143.     shiftOn = ( (theEvent->modifiers & shiftKey) != 0);
  144.     FocusOnWindow();
  145.     GlobalToLocal(&theEvent->where);
  146.     GetContentRect(&contents);
  147.     if(PtInRect(theEvent->where, &contents))
  148.     {        
  149.         TEClick(theEvent->where, shiftOn, fDocText);
  150.     }// end if in content rect
  151.     else
  152.         ScrollClick(theEvent);
  153.  
  154. }// end of DoContent function
  155.  
  156.  
  157. void    DTEditWind::Draw(Rect *r)
  158. {
  159.     if( fDocText)
  160.     {
  161.         EraseRect(r);
  162.         TEUpdate(r, fDocText);
  163.     }
  164.     
  165. }// end of Draw member function
  166.  
  167.  
  168. // the grow methods only need to update the viewRect for the TEHandle
  169. void    DTEditWind::DoGrow(EventRecord *theEvent)
  170. {
  171.     Rect r;
  172.     
  173.     inherited::DoGrow(theEvent);
  174.     
  175.     GetContentRect(&r);
  176.     (**fDocText).viewRect = r;
  177.     
  178. }// end of DoGrow override
  179.  
  180. void    DTEditWind ::DoZoom(short partCode)
  181. {
  182.     Rect r;
  183.  
  184.     inherited::DoZoom(partCode);
  185.     
  186.     GetContentRect(&r);
  187.     (**fDocText).viewRect = r;
  188.     
  189. }// end of DoZoom member function
  190.  
  191.  
  192.  
  193. void    DTEditWind::ScrollContents(short dh, short dv)
  194. {
  195.  
  196.     TEScroll(dh, dv, fDocText );
  197.     
  198.     fVOffSet = (*fDocText)->viewRect.top - (*fDocText)->destRect.top;
  199.     fHOffSet = (*fDocText)->viewRect.left - (*fDocText)->destRect.left;
  200.     
  201. }// end of ScrollContents function
  202.  
  203.  
  204. void    DTEditWind::FocusOnContent(void)
  205. {
  206.     Rect r;
  207.     
  208.     SetPort(fWindowPtr);
  209.     GetContentRect(&r);
  210.     ClipRect(&r);
  211.     
  212. }// end of FocusOnContent member
  213.